package com.aaa.pro.dao;

import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * fileName:ProductDao
 * description:
 * author:MT
 * createTime:2020/1/12 19:42
 * version:1.0.0
 */
public interface ProductDao {

    /**
     * 根据条件查询商品信息
     * @param map
     * @return LIKE CONCAT('%',#{name},'%') CONCAT('%',CONCAT(#{proName},'%'))
     */
    @Select("<script>select id,name,pic,sale,price,promotion_price as promotionPrice,product_category_id as categoryId,sub_title as subtitle " +
            "from pms_product where shop_id = #{shopId} and publish_status = 1" +
            "<if test=\"categoryId != null and categoryId != ''\"> and product_category_id = #{categoryId} </if>" +
            "<if test=\"pname != null and pname != ''\"> and name LIKE CONCAT('%',#{pname},'%') </if>" +
            "</script>")
    List<Map> getProducts(Map map);

    /**
     * 根据店铺id查询商品分类
     * @param shopId
     * @return
     */
    @Select("select id,name from pms_product_category where shop_id = #{shopId} and show_status = 1 ")
    List<Map> getProductCategory(Long shopId);
    /**
     * 根据ID查询商品详情
     * @param map
     * @return
     */
    @Select("select * from pms_product where shop_id = #{shopId} and id = #{productId} and currency = #{currency}")
    Map getProductById(Map map);

    /**
     * 查询店铺下的积分商品
     */
    @Select("select * from pms_product where shop_id = #{shopId} and currency = 1")
    List<Map> listIntegralPro(long shopId);

    @Select("select id,name,price,sub_title,description,stock,DATE_FORMAT(t.promotion_start_time,'%Y-%m-%d') as promotion_start_time,DATE_FORMAT(t.promotion_end_time,'%Y-%m-%d') as promotion_end_time from pms_product t where id = #{id}")
    Map getProById(Long id);
}
